package cn.tedu.order.management.dao.persist.repository.impl;

import cn.tedu.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.common.util.PageInfoToPageDataConverter;
import cn.tedu.order.management.dao.persist.mapper.AddCnmd;
import cn.tedu.order.management.dao.persist.mapper.OrderMapper;
import cn.tedu.order.management.dao.persist.repository.IOrderRepository;
import cn.tedu.order.management.pojo.entity.Order;
import cn.tedu.order.management.pojo.vo.OrderAdminListVO;
import cn.tedu.order.management.pojo.vo.OrderStaffListVO;
import cn.tedu.order.management.pojo.vo.UserOrderVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderRepositoryImpl implements IOrderRepository {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private AddCnmd addCnmd;

    @Override
    public int addcnmd(Order order) {
        return addCnmd.addcnmd(order);
    }


    @Override
    public int deleteById(Long id) {
        return orderMapper.deleteById(id);
    }

    @Override
    public PageData<OrderAdminListVO> listForAdmin(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderAdminListVO> list = orderMapper.listForAdmin();
        PageInfo<OrderAdminListVO> pageInfo = new PageInfo(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public UserOrderVO listUserById(Long id) {
        return orderMapper.listUserById(id);
    }

    @Override
    public List<UserOrderVO> list(Long userId) {
        return orderMapper.list(userId);
    }

    @Override
    public int updateState(Order order) {
        return orderMapper.updateState(order);
    }

    @Override
    public PageData<OrderStaffListVO> listForStaff(Long id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderStaffListVO> list = orderMapper.listForStaff(id);
        PageInfo<OrderStaffListVO> pageInfo = new PageInfo(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }


}
